package com.example.controller;

import lombok.extern.slf4j.Slf4j;
// import org.springframework.ai.openai.OpenAiChatModel; //private OpenAiChatModel chatModel;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class ChatDeepSeekController {

    /**
     *  调用chat模型
     */
    @Autowired
    private OllamaChatModel ollamaChatModel;



    @GetMapping("/ai/chat")
    public String chat(@RequestParam(value = "message", defaultValue = "hello")
                       String message) {
        log.info("begin to chat method, message: {}", message);
        String response = this.ollamaChatModel.call(message);
        log.info("end to chat method, response: {}", response);
        return response;
    }

    @Autowired
    private ChatClient chatClient;
    @GetMapping("/ai/joke")
    public String joke(@RequestParam(value = "msg",defaultValue = "给我讲个笑话")
             String message) {
        log.info("begin to chat method, message: {}", message);
        //prompt:提示词
        String content = this.chatClient.prompt()
                //用户输入的信息
                .user(message)
                //请求大模型
                .call()
                //返回文本
                .content();
        log.info("end to chat method, response: {}", content);
        return content;
    }
}